package com.tongfusoft.document.personalCenter.myFollow.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.tongfuosft.document.system.notice.service.INoticeService;
import com.tongfusoft.da.pagehelper.PageInfo;
import com.tongfusoft.da.template.service.impl.DataTemplateServiceImpl;
import com.tongfusoft.document.entity.Docs;
import com.tongfusoft.document.entity.Notice;
import com.tongfusoft.document.entity.UserFollows;
import com.tongfusoft.document.entity.Users;
import com.tongfusoft.document.personalCenter.myFollow.service.IMyFollowService;
import com.tongfusoft.utils.UIDGeneratorService;

@Service("userFollowService")
public class MyFollowServiceImpl extends DataTemplateServiceImpl implements IMyFollowService{
	
	@Autowired
	@Qualifier("noticeService")
	public INoticeService noticeService;
	
	@Override
	public PageInfo<Docs> follow(Users user,UserFollows userFollows ,int pageSize,int pageIndex) { 
		userFollows.setCreatedBy(user.getUserId());
		userFollows.setSelectUser(user.getUserId());
		return super.findPage("userFollowsList", userFollows, pageSize, pageIndex);
	}

	@Override
	public void delUserFollowDoc(UserFollows userFollows, Users user) {
		Notice notice = new Notice();
		notice.setDocName(userFollows.getDocName());
		notice.setUserId(user.getUserId());
		this.noticeService.delNotice(notice, user);
		this.delete("delUserFollows", userFollows);
	}

	@Override
	public void createUserFollow(UserFollows userFollows, Users user) {
		userFollows.setCreatedBy(user.getUserId());
		userFollows.setCreatedDate(new java.sql.Timestamp(new java.util.Date().getTime()));
		userFollows.setLastUpdBy(user.getUserId());
		userFollows.setLastUpdDate(new java.sql.Timestamp(new java.util.Date().getTime()));
		userFollows.setFollowId(UIDGeneratorService.getUUID());
		userFollows.setStatus("1");
		this.insert("addUserFollows", userFollows);
	}

	@Override
	public UserFollows getUserFollow(UserFollows userFollows) {
		return (UserFollows) this.selectOne("getUserFollow", userFollows);
	}

	@Override
	public List<UserFollows> getUserByDocName(UserFollows userFollows) {
		return this.selectList("getUserId", userFollows);
	}

}
